package com.pansoft.kline.base;

import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import androidx.viewpager.widget.ViewPager;
import android.widget.ImageView;
import android.widget.TextView;

import com.efounder.chat.activity.BaseActivity;
import com.efounder.frame.baseui.BaseFragment;
import com.pansoft.kline.adapter.ViewPagerAdapter;
import com.pansoft.openplanet.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : zzj
 * @e-mail : zhangzhijun@pansoft.com
 * @date : 2018/12/3 9:42
 * @desc :  带有顶部菜单 左右滑动的baseactivity
 * @version: 1.0
 */
public abstract class BaseViewPagerActivity extends BaseActivity {

    protected TabLayout tabLayout;

    protected ViewPager viewPager;

    protected TextView tv_title;

    protected ImageView back;

    protected ViewPagerAdapter adapter;

    protected List<BaseFragment> mFragments;

    protected List<String> mTitles;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_viewpager);
        initView();
    }

    protected void initView(){
        tabLayout = (TabLayout) findViewById(R.id.tab);
        viewPager = (ViewPager) findViewById(R.id.viewpager);
        tv_title = (TextView) findViewById(R.id.tv_title);
        back = (ImageView) findViewById(R.id.iv_close);
        mTitles = new ArrayList<>();
        mFragments = new ArrayList<>();

        initData();
    }

    /**
     * 加载数据
     */
    protected abstract void initData();
    /**
     * 初始化adapter
     */
    protected void initAdapter(){
        adapter = new ViewPagerAdapter(getSupportFragmentManager(), createFragments(), mTitles);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    /**
     * 顶部title集合
     *
     * @return String[]
     */
    protected abstract List<String> createPageTitle();

    /**
     * 创建列表fragment
     *
     * @return List<BaseFragment>
     */
    protected abstract List<BaseFragment> createFragments();

    /**
     * 标题
     * @param titleName
     */
    protected void setTitle(String titleName) {
        tv_title.setText(titleName);
    }
}
